package com.example.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;

/**
 * @author : zhayh
 * @date : 2021-5-4 21:28
 * @description :
 */

//@Configuration
public class RabbitMQTopicConfig {
    @Bean
    Queue marketingQueue() {
        return new Queue("marketingQueue");
    }
    @Bean
    Queue financeQueue() {
        return new Queue("financeQueue");
    }
    @Bean
    Queue adminQueue() {
        return new Queue("adminQueue");
    }
    @Bean
    Queue allQueue() {
        return new Queue("allQueue");
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("topic-exchange");
    }

    @Bean
    Binding marketingBinding(Queue marketingQueue, TopicExchange exchange) {
        return BindingBuilder.bind(marketingQueue)
                .to(exchange)
                .with("queue.marketing");
    }

    @Bean
    Binding financeBinding(Queue financeQueue, TopicExchange exchange) {
        return BindingBuilder.bind(financeQueue)
                .to(exchange)
                .with("queue.finance");
    }

    @Bean
    Binding adminBinding(Queue adminQueue, TopicExchange exchange) {
        return BindingBuilder.bind(adminQueue)
                .to(exchange)
                .with("queue.admin");
    }
    @Bean
    Binding allBinding(Queue allQueue, TopicExchange exchange) {
        return BindingBuilder.bind(allQueue)
                .to(exchange)
                .with("queue.*");
    }
}
